package com.dlm.sdk.api;

import com.jfinal.kit.HttpKit;
import com.jfinal.kit.PropKit;

/**
 * menu api
 */
public class MenuApi {
	
	private static String getMenu = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=";
	private static String createMenu = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=";
	
	/**
	 * 查询菜单
	 */
	public static ApiResult getMenu() {
		String jsonResult = HttpKit.get(getMenu + AccessTokenApi.getAccessToken().getAccessToken());
		return new ApiResult(jsonResult);
	}
	
	/**
	 * 创建菜单
	 */
	public static ApiResult createMenu(String jsonStr) {
		String jsonResult = HttpKit.post(createMenu + AccessTokenApi.getAccessToken().getAccessToken(), jsonStr);
		return new ApiResult(jsonResult);
	}

	public static void main(String[] args) {
		ApiConfig ac = new ApiConfig();
		// 配置微信 API 相关常量
		ac.setToken("dlm");
		ac.setAppId("wxc6f57a1be5f8d68a");
		ac.setAppSecret("21274d8056d534d644534a1bef201569");
		ac.setEncryptMessage(false);
		ac.setEncodingAesKey("lVHU1W0m63i0tYJ1C65NfFlrZYyk4onC9OnqvScr443");
		ApiConfigKit.setThreadLocalApiConfig(ac);

		String json = "{ \"button\": [ { \"name\": \"预约美容\", \"type\": \"view\", \"url\": \"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc6f57a1be5f8d68a&redirect_uri=http://meirongdaojia.com&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect\" }, { \"name\": \"喵喵社区\", \"sub_button\": [ { \"type\": \"view\", \"name\": \"喵喵社区\", \"url\": \"http://wsq.qq.com/reflow/264415339\" }, { \"type\": \"view\", \"name\": \"意见建议\", \"url\": \"http://m.wsq.qq.com/264415339/t/new?filterType=150245\" } ] }, { \"name\": \"服务中心\", \"sub_button\": [ { \"type\": \"view\", \"name\": \"个人中心\", \"url\": \"http://www.meirongdaojia.com/#/user/home\" }, { \"type\": \"view\", \"name\": \"我的订单\", \"url\": \"http://www.meirongdaojia.com/#/user/order\" } ] } ] }";
		ApiResult menu = MenuApi.createMenu(json);
		System.out.println();
	}
}


